package com.ctshk.rpc.starvip.util;

import com.alibaba.fastjson.JSON;
import com.ctshk.common.enums.SystemError;
import com.ctshk.common.exception.BusinessException;
import com.ctshk.rpc.starvip.factory.StarVipReqProvider;

/**
 * @BelongsProject: ctshk-cloud
 * @BelongsPackage: com.ctshk.rpc.starvip.util
 * @Author: hef
 * @CreateTime: 2021-04-12 18:01
 * @Description: 描述
 */
public class ReqUtil {
    /**
     * 发请求
     * @param provider
     * @return
     */
    public static String sendReq(StarVipReqProvider provider){
        String result = null;
        try {
            System.out.println(String.format("集团会员请求信息:%s", JSON.toJSONString(provider)));
            result = IBMMqUtil.send(provider);
            System.out.println(String.format("集团会员返回信息:%s", result));
        } catch (Exception e) {
            e.printStackTrace();
            throw new BusinessException(SystemError.STAR_VIP_20000, e.getMessage());
        }
        return result;
    }

    /**
     * xml转对象
     * @param clazz
     * @param xmlStr
     * @param <T>
     * @return
     */
    public static <T> T fromXml(Class<T> clazz,String xmlStr){
        JaxbUtil jaxbUtil = new JaxbUtil(clazz);
        return jaxbUtil.<T>fromXml(xmlStr);
    }

}
